package com.hjk.waibao.mj.util.wechatpay;

import com.jfinal.kit.PropKit;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;

/**
 * @Description
 * @Author hjk
 * @Date 2020/5/12
 **/
public class WechatPayConfig extends WXPayConfig {

    private byte[] certData;
    public static String appId = PropKit.get("wechat.officialAccounts.id");
    private static String key = PropKit.get("wechatpay.apiv3Secret");
    private static String mchId = PropKit.get("wechatpay.mchId");
    private static WechatPayConfig instance = new WechatPayConfig();

    private WechatPayConfig() {
        try {
            String certPath = "wechatpay_cert/apiclient_cert.p12";
            File file = new File(certPath);
            InputStream certStream = new FileInputStream(file);
            this.certData = new byte[(int) file.length()];
            certStream.read(this.certData);
            certStream.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public static WechatPayConfig getInstance() {
        return instance;
    }

    public String getAppID() {
        return appId;
    }

    public String getMchID() {
        return mchId;
    }

    public String getKey() {
        return key;
    }

    public InputStream getCertStream() {
        ByteArrayInputStream certBis = new ByteArrayInputStream(this.certData);
        return certBis;
    }

    public int getHttpConnectTimeoutMs() {
        return 8000;
    }

    public int getHttpReadTimeoutMs() {
        return 10000;
    }

    @Override
    IWXPayDomain getWXPayDomain() {
        return WXPayDomainSimpleImpl.instance();
    }
}
